package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.modeler.model.core.MetaPackage;
import edu.pku.sei.transformation.editor.internal.TransformationEditorModelRoot;
import edu.pku.sei.transformation.editor.model.MetaModel;

public class MetaModelDeleteCommand extends Command {
	private MetaModel model;
	private edu.pku.sei.modeler.model.core.MetaModel projectModel;
	private MetaPackage metamodelPackage;
	public MetaModelDeleteCommand(MetaModel model, edu.pku.sei.modeler.model.core.MetaModel projectModel) {
		this.model = model;
		this.projectModel = projectModel;
		this.metamodelPackage = TransformationEditorModelRoot.getMetaModelPkg(projectModel);
	}
	
	@Override
	public boolean canExecute() {
		if (model == null || metamodelPackage == null) {
			return false;
		} 
		return super.canExecute();
	}
	
	@Override
	public void execute() {
		metamodelPackage.getNamedElements().remove(model);
	}
	
	@Override
	public void undo() {
		metamodelPackage.getNamedElements().add(model);
	}
}
